#include<bits/stdc++.h>
#define int long long 
using namespace std;
const int N=3e4+5;
int n,len;
int a[N],pre[N],suf[N];
int check(int x){
	if(!len)return 0;
	if(x>a[len])return 0;
	int y=lower_bound(a+1,a+len+1,x)-a;
	if(x==a[y])return y;
	else return 0;
}
void SUB1(){
	set<int>s;
	int sum=0,cnt=0;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		if(s.find(x)!=s.end())s.erase(x),sum-=x,cnt--;
		else s.insert(x),sum+=x,cnt++;
		if(i<=30000){
			int w=check(x);
			if(w){
				len--;
				for(int i=w;i<=len;i++)swap(a[i],a[i+1]);
			}else{
				a[++len]=x;
				int now=len; 
				while(now>1&&a[now]<a[now-1])swap(a[now],a[now-1]),now--;
			}
			pre[0]=0;for(int i=1;i<=len;i++)pre[i]=pre[i-1]+a[i];
			suf[len+1]=0;for(int i=len;i>=1;i--)suf[i]=suf[i+1]+a[i];
			int ans=0,last=0;
			for(int i=1;i<len;i++){
				ans-=max(last-pre[i],0ll);
				ans+=suf[len-i+1]-pre[i];
				last=suf[len-i+1];
			}
			cout<<ans<<'\n';
		}else{
			if(cnt>=2)cout<<sum-2ll*(*s.begin())<<'\n';
			else cout<<0<<'\n';
		}
	}
}
signed main(){
	ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    freopen("kte.in","r",stdin);
    freopen("kte.out","w",stdout);
    cin>>n;
    SUB1();
	return 0;
}
